<template>
  <div>
 <my-header title="购物车" @onClickLeft="$router.push('/my')"/>
<div v-for="(text,index) in list" :key='index' >
  <van-row class="dianpu">
    <van-col span="2" class="toggle">
      <!-- <input id="toggle" type="checkbox"> -->
      </van-col>
    <van-col span="8">
      <span>{{text.storeName}}</span>
      <p >{{text.storeMobile}}</p>
    </van-col>
    <van-col span="14">
      <van-icon name="location" color="#0039fd"/><span>{{text.storeAddress}}</span>
      <p class="shoujihao">距离：{{text.distance}}m<van-icon name="delete" class="shanchu" /></p>
    </van-col>
  </van-row>
  <div class="shangpin-zhanshi">
  <p class="xuangoods">选购商品</p>
  <van-row class="xuangou">
    <van-col span="2"  class="toggl">
      <!-- <input id="toggle" type="checkbox"> -->
      </van-col>
    <van-col span="12"><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg1.99114.com%2Fgroup1%2FM00%2F0B%2F5C%2FwKgGS1jB_NWAKoBhAAjSFh9HBj4055.jpg&refer=http%3A%2F%2Fimg1.99114.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1617881512&t=755c64f9836daa6579d9b2f6fcca17bd" ><p>{{text.goodsname}}</p></van-col>
    <van-col span="6"><van-stepper v-model="text.value" integer  @change="aaa()"/></van-col>
    <van-col span="4"><p>￥{{text.value*28.8}}</p></van-col>
  </van-row>
  <van-cell class="fuwu" title="包装" :value="text.baozhuangfei" />
  <van-cell class="fuwu" title="配送上门" :value="text.peisongfei" />
  <van-cell class="fuwu" title="合计：" :value="xiaoji(text)" />
</div>
</div>
<van-submit-bar :price="zongji" button-text="提交订单" @submit="$router.push('/my/order')">
  <van-badge :content="a">
  <van-icon name="shopping-cart-o" class="shopping-cart" />
</van-badge>
</van-submit-bar>
  </div>
</template>

<script>
import { getCart } from '@/api/my-liang'
import { mapState, mapMutations } from 'vuex'
import MyHeader from '../components/my-header.vue'
export default {
  name: '',
  components: {
    MyHeader
  },
  props: {},
  data () {
    return {
      // goodsname: '猪肉500g',
      // storeName: '',
      // storeMobile: null,
      // storeAddress: '',
      // distance: '',
      // value: 1,
      // baozhuangfei: '￥2',
      // peisongfei: '￥2'
      // list: [],
      // xiaojiArr: []
      zongji: 0,
      content: '',
      // x: 0,
      a: 0 // value 总计
    }
  },
  watch: {
  },
  created () {
    this.getInfo()
  },
  computed: {
    ...mapState('m_liang', ['list'])
    // heji1 () {
    //   if (this.heji === '￥0') {
    //     return 0
    //   } else {
    //     this.x = 0
    //     this.list.forEach((item) => {
    //       console.log(item.value)
    //       this.x += item.value
    //       return zongjia += parseFloat(this.xiaoji(item).substring(1))
    //     })
    //     console.log(x)
    //     return parseFloat(this.xiaoji().substring(1)) * 100
    //     console.log(this.x)
    //     return 0
    //   }
    // }
  },
  mounted () {

  },
  methods: {
    ...mapMutations('m_liang', ['savelist']),
    xiaoji (item) {
      if (item) {
        var m = (parseFloat(item.baozhuangfei.substring(1)) + parseFloat(item.peisongfei.substring(1)) + item.value * 28.8).toFixed(2)
        // this.zongji += m
        // console.log(m)
        // this.x += m
        // console.log(this.x)
        return '￥' + m
      }
    },
    async getInfo () {
      try {
        const { data } = await getCart()
        // this.list = data
        this.savelist(data)
        console.log(data)
        this.aaa()
      } catch (error) {
        this.$toast('获取数据失败, 请稍后重试')
      }
    },
    // heji (item) {
    //   if (item) {
    //     this.zongji += parseFloat(this.xiaoji(item).substring(1)) * 100
    //   }
    // },
    aaa () {
      this.a = 0
      this.zongji = 0
      this.list.forEach(i => {
        this.a += i.value
        this.zongji += parseFloat(this.xiaoji(i).substring(1)) * 100
      })
      console.log(this.a)
      console.log(this.zongji)
    }
  }
}
</script>

<style scoped lang="less">
.dingbu{
    border-bottom: 4px solid #02b6fd;
}
 /deep/ .van-icon-arrow-left::before {
    font-size: 40px;
    font-weight: 700;
    color: #333 ;
  }
  .dianpu{
      font-size: 28px;
      padding: 10px;
      border-bottom: 2px solid #02b6fd;
      border-top: 2px solid #02b6fd;
      .toggle{
        padding: 25px 8px;
      }
      .shoujihao{
          position: relative;
          margin: 5px 0;
          .shanchu{
              position: absolute;
              right: 10px;
              font-size: 48px;
          }
      }
  }
  .shangpin-zhanshi{
      border-bottom: 2px solid #02b6fd;
  }
  .xuangou{
      font-size: 28px;
      img{
          margin-right: 20px;
          width: 100px;
          height: 100px;
      }
      .toggl{
          margin-top: 20px;
          padding: 10px 5px;
      }
      p{
          display: inline-block;
      }
  }
  .xuangoods{
      font-size: 32px;
  }
  .van-cell::after{
      border: none ;
  }
  .shopping-cart{
      font-size: 50px;
  }
  .van-submit-bar{
      border-top: 1px solid;
  }
  .shangpin-zhanshi[data-v-4c84174a] {
    margin-bottom: 100px;
  }
</style>
